#!/bin/bash
# 命令行打开 pdf 文档
# Ctrl + W可关闭文件

### Description:
###     Pdf — use atril to open pdf while avoiding error message.
###
### Date: 2020.07.09
### Author: Shieber
### Email: QMH_XB_FLTMY@yahoo.com
###
### Usage:
###     Pdf  <file>
###
### Options:
###     <file>     Input a pdf file
###     -h,--help   Show help message.
###
### Example:
###     Pdf file.pdf
help() {
    sed -rn 's/^### ?//;T;p' "$0"
}


if [[ $# == 0 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
    help
    exit 1
else                                #有参数，打开文件
    if [ "${1##*.}" = "pdf" ]; then
        atril $1 >/dev/null 2>&1 &  #用atril打开pdf，忽略各种错误信息
    else
        echo 'Wrong file format, need [xxx.pdf]'
        exit 1
    fi
fi
